import tools from '../../../utils/tools'
import Handle from './Handle'
/**
 * 负责列表按钮事件处理
 */
@tools
export default class Event {
  constructor(oCart, courseData, cartData, observer) {
    this.oCart = oCart
    this.courseData = courseData
    this.cartData = cartData
    this.observer = observer

    this.init()
  }
  init() {
    this.bindEvent()

    this.handle = new Handle(this.courseData, this.cartData,this.oCart, this.observer)
  }
  /**
   * 绑定事件
   */
  bindEvent() {
    // 添加购物车按钮
    this.oCart.addEventListener(
      'click',
      this.onRemoveBtnClick.bind(this),
      false
    )
  }
  onRemoveBtnClick(e) {
    // 获取当前点击的按钮
    const tar = Event.getTarget(e),
      className = tar.className
    if (className === 'remove-btn') {
      const id = tar.getAttribute('data-id')
      this.observer.notify(this,id,tar,0)
    }
  }
}
